Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Flutter lint #253

Merged
merged 24 commits into from
Mar 4, 2025
Merged

Add Flutter lint #253

merged 24 commits into from
Mar 4, 2025

Conversation

jasikpark
Copy link
Contributor

@jasikpark jasikpark commented Feb 13, 2025

Add https://pub.dev/packages/flutter_lints and fix the complaining lints

See https://dart.dev/tools/analysis#lints for more

This surfaced two package imports that weren't tracked by pubspec.yaml: path was imported w/o being registered as a dep, and flutter_web_plugins, an internal tool of Flutter, was being imported, and needed a manually added dependency.

@jasikpark jasikpark force-pushed the flutter-lint branch 3 times, most recently from 408c287 to 0f457d3 Compare February 13, 2025 20:20
@jasikpark jasikpark force-pushed the flutter-lint branch 2 times, most recently from e32b93e to 317c607 Compare February 13, 2025 20:54
Base automatically changed from flutter-fmt to main February 13, 2025 21:37
@jasikpark jasikpark marked this pull request as ready for review February 13, 2025 21:40
import 'package:mobile_nebula/services/theme.dart';
import 'package:mobile_nebula/services/utils.dart';
import 'package:sentry_flutter/sentry_flutter.dart';

Future<void> main() async {
usePathUrlStrategy();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to git blame (https://github.com/DefinedNet/mobile_nebula/blame/bcfcadec8ef46f2ed628ab9334088e1f142f22a6/lib/main.dart#L18), this was added as part of the work to support DN enrollment. We need to be able to process a url deep-link when enrolling, so I do not think we can remove this package or this line.

Copy link
Contributor

@IanVS IanVS Feb 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW I think this is the only real blocker here. (And maybe the concatenation one, depending on whether that format actually works or not in dart.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iOS at least works with this removed, the correct page is opened.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe https://github.com/stryder-dev/flutter_platform_widgets/wiki/Routing may handle this instead, not requiring importing an un-exported function.

(context) => PlatformApp(
debugShowCheckedModeBanner: false,
localizationsDelegates: <LocalizationsDelegate<dynamic>>[
DefaultMaterialLocalizations.delegate,
DefaultWidgetsLocalizations.delegate,
DefaultCupertinoLocalizations.delegate,
],
title: 'Nebula',
material: (_, __) {
return new MaterialAppData(
themeMode: brightness == Brightness.light ? ThemeMode.light : ThemeMode.dark,
theme: brightness == Brightness.light ? theme.light() : theme.dark(),
);
},
cupertino: (_, __) => CupertinoAppData(theme: CupertinoThemeData(brightness: brightness)),
onGenerateRoute: (settings) {
if (settings.name == '/') {
return platformPageRoute(context: context, builder: (context) => MainScreen(this.dnEnrolled));
}
final uri = Uri.parse(settings.name!);
if (uri.path == EnrollmentScreen.routeName) {
// TODO: maybe implement this as a dialog instead of a page, you can stack multiple enrollment screens which is annoying in dev
return platformPageRoute(
context: context,
builder:
(context) =>
EnrollmentScreen(code: EnrollmentScreen.parseCode(settings.name!), stream: this.dnEnrolled),
);
}
return null;
},
),
);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by "importing an un-exported function"? What is being done here is what the docs show: https://docs.flutter.dev/ui/navigation/url-strategies#configuring-the-url-strategy

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trying to get my android emulator to work for testing...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

ah, appreciate that the deeplink validator works...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by "importing an un-exported function"? What is being done here is what the docs show: docs.flutter.dev/ui/navigation/url-strategies#configuring-the-url-strategy

We needed to add the package as a direct dependency, rather than indirectly importing it as part of the flutter sdk.

image

Added that dep to pubspec.yaml and everything's all good now.

@@ -11,51 +11,51 @@ class MaterialTheme {
static ColorScheme lightScheme() {
return const ColorScheme(
brightness: Brightness.light,
primary: Color(4284700303),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should ignore this file, since it was auto-generated and it will be easier to compare changes in the future if we don't muck around with it too much.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -41,10 +41,10 @@ class Utils {

static String itemCountFormat(int items, {singleSuffix = "item", multiSuffix = "items"}) {
if (items == 1) {
return items.toString() + " " + singleSuffix;
return "$items " + singleSuffix;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still using concatenation, and does it need to be ${items}? (same below)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this syntax works ${...} syntax is only needed for complex expressions, so ${items+1} v.s.$items.

https://learnxbyexample.com/dart/text-templates/

Copy link
Contributor

@IanVS IanVS Mar 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, but, shouldn't this still be `${items} ${singleSuffix}`?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, whoops forgot to actually augment the autofix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❯ jj absorb  
Absorbed changes into these revisions:
  povmpvpx 93f7cc15 `dart fix --apply --code=prefer_interpolation_to_compose_strings`
Rebased 10 descendant commits.
Working copy now at: wusutqos b0d3d23d (no description set)
Parent commit      : pxwtotsz 05879848 flutter-lint* | `dart format lib/`
Remaining changes:
M lib/services/utils.dart

Love that I can use jj absorb to automatically include the fix in the associated commit it should have been in. Works 70% of the time 100% of the time!

@@ -11,7 +11,7 @@ bool DEFAULT_TRACK_ERRORS = true;
class Settings {
final _storage = Storage();
final StreamController _change = StreamController.broadcast();
var _settings = Map<String, dynamic>();
var _settings = <String, dynamic>{};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a huge fan of this rule, seems stylistic and more obtuse, but if that's the recommended way, I guess we can roll with it. Just seems like there's no good reason not to be explicit. /shrug

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave it enabled. not a fan, but i like keeping the config to a min over customizing.

@jasikpark jasikpark requested a review from IanVS March 4, 2025 00:29
@jasikpark jasikpark merged commit 2b844d2 into main Mar 4, 2025
5 checks passed
@jasikpark jasikpark deleted the flutter-lint branch March 4, 2025 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants